package cqrtplm.service.impl;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import cqrtplm.constant.IpAddressConstant;
import cqrtplm.dto.thirdPartyAPI.RestAdapterMomDTO;
import cqrtplm.dto.thirdPartyAPI.RestAdapterMomOrderDTO;
import cqrtplm.service.MomApiService;
import cqrtplm.vo.CrmApiResponseVO;
import cqrtplm.vo.MomApiResponseVO;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: zhengxiong.jiang
 * @createDate: 2025-10-23
 * @version: 1.0
 */
@Service
public class MomApiServiceImpl implements MomApiService {


    @Override
    public MomApiResponseVO restInvoke(RestAdapterMomDTO dto) {

        String body = HttpRequest.post(IpAddressConstant.MOM_CS_ZTKZ_CQ)
                .header("Content-Type", "application/json")
                .body(JSONUtil.toJsonStr(dto))
                .execute().body();

        MomApiResponseVO momApiResponseVO = JSONUtil.toBean(body, new TypeReference<MomApiResponseVO>() {}, false);

        return momApiResponseVO;
    }

    @Override
    public MomApiResponseVO getOrder(RestAdapterMomOrderDTO dto) {

        String body = HttpRequest.post(IpAddressConstant.MOM_CS_DD_CQ)
                .header("Content-Type", "application/json")
                .body(JSONUtil.toJsonStr(dto))
                .execute().body();

        MomApiResponseVO<MomApiResponseVO.MomOrderDTO> momApiResponseVO = JSONUtil.toBean(body, new TypeReference<MomApiResponseVO<MomApiResponseVO.MomOrderDTO>>() {}, false);

        return momApiResponseVO;
    }
}
